jQuery(window).load(function(){
    var rightBoxHeight      = jQuery('.viewright').height(),
        //viewright           = jQuery(".viewright").offset().top;
    jQuery(window).scroll(function() {
        var scroH           = jQuery(window).scrollTop(),
            mainpart        = jQuery('.mainpart'),
            mainboxoffset   = mainpart.offset().top,
            mainboxheight   = mainpart.height(),
            difference      = mainboxheight-(rightBoxHeight+10)+mainboxoffset,
            readerboxObj    = jQuery('.readerbox'),
            viewrightObj    = jQuery('.viewright');
        if(scroH>=viewright && scroH<difference){
			readerboxObj.fadeIn();
            viewrightObj.css({"position":"fixed","top":"0px","margin-left":"900px"}).fadeIn();
        }else if(scroH>difference){
			readerboxObj.fadeOut(100);
            viewrightObj.fadeOut(100);
        }else{
			readerboxObj.fadeOut(100);
            viewrightObj.attr("style","");
        }
    });
});

jQuery('body').on("click", ".doc_share", function () {
    var share_menu=jQuery('.keke_share_menu');
    if(share_menu.is(':hidden')){
        share_menu.fadeIn();
    }else{
        share_menu.hide();
    }
});

jQuery('body').on("click", ".js-social-share", function () {
    var e = jQuery(this),
        a = e.data("share"),
        i = e.parents(".keke_share_menu").data(),
        n = "",
        p = jQuery(".point-share-url");
    switch (p.length > 0 && jQuery.post(p.val(), function () {}), a) {
        case "weibo":
            n = r(i), window.open(n);
            break;
        case "qzone":
            n = t(i), window.open(n);
            break;
        case "qq":
            n = o(i), window.open(n);
            break;
        case "weixin":
            s(e)
    }
})

jQuery('body').on("click", ".doc_mobile", function () {	
    s(jQuery('.weixinshare'));
});

function s(e) {
    layer.open({
        type: 1,
        title: false,
        closeBtn: 0,
        shadeClose: true,
        content: '<div class="weixinsharebox"><img src="'+e.data('qrcode-url')+'" alt="" width="200"><br>请使用手机扫一扫</div>'
    });
}
function r(e) {
    var a = {};
    return a.url = e.url, a.title = e.message, "" != e.picture && (-1 != e.picture.indexOf("://") ? a.pic = e.picture : a.pic = document.domain + e.picture), "http://service.weibo.com/share/share.php?" + d(a)
}

function t(e) {
    var a = {};
    return a.url = e.url, a.title = e.title, a.summary = e.summary, a.desc = e.message, "" != e.picture && (a.pics = e.picture), "http://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey?" + d(a)
}

function o(e) {
    var a = {};
    return a.url = e.url, a.title = e.title, a.summary = e.summary, a.desc = e.message, "" != e.picture && (a.pics = e.picture), "http://connect.qq.com/widget/shareqq/index.html?" + d(a)
}

function d(e) {
    var a = [];
    for (var i in e) a.push(i + "=" + encodeURIComponent(e[i] || ""));
    return a.join("&")
}
